//
//  UIFont+Adapt.m
//  蓝黑黑
//
//  Created by 崔国冠 on 2017/5/12.
//  Copyright © 2017年 崔国冠. All rights reserved.
//

#import "UIFont+Adapt.h"
#import "NSObject+Swizzle.h"

@implementation UIFont (Adapt)
#define IS_IPHONE_6 ([[UIScreen mainScreen] bounds].size.height == 667.0f)
#define IS_IPHONE_6_PLUS ([[UIScreen mainScreen] bounds].size.height == 736.0f)
#define IS_IPHONE_X ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) : NO)

+(void)load {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        [objc_getClass("UIFont") swizzleClassSelector:@selector(systemFontOfSize:) withSwizzledSelector:@selector(yy_systemFontOfSize:)];
        [objc_getClass("UIFont") swizzleClassSelector:@selector(boldSystemFontOfSize:) withSwizzledSelector:@selector(yy_boldSystemFontOfSize:)];
    });
}



+(UIFont *)yy_systemFontOfSize:(CGFloat)fontSize {
    UIFont *newFont = nil;
    if (IS_IPHONE_6){
        newFont = [UIFont yy_systemFontOfSize:fontSize + 1];
    } else if (IS_IPHONE_6_PLUS){
        newFont = [UIFont yy_systemFontOfSize:fontSize + 2];
    } else if (IS_IPHONE_X){
        newFont = [UIFont yy_systemFontOfSize:fontSize + 1];
    }  else {
        newFont = [UIFont yy_systemFontOfSize:fontSize];
    }
    return newFont;
}

+(UIFont *)yy_boldSystemFontOfSize:(CGFloat)fontSize {
    UIFont *newFont = nil;
    if (IS_IPHONE_6){
        newFont = [UIFont yy_boldSystemFontOfSize:fontSize + 1];
    } else if (IS_IPHONE_6_PLUS){
        newFont = [UIFont yy_boldSystemFontOfSize:fontSize + 2];
    } else if (IS_IPHONE_X){
        newFont = [UIFont yy_boldSystemFontOfSize:fontSize + 1];
    } else {
        newFont = [UIFont yy_boldSystemFontOfSize:fontSize];
    }
    return newFont;
}

@end






